const { onMsg, request } = require(`${process.root}/util`);
const CONFIG = require(`${process.root}/config`);
const baseUrl = CONFIG.bot.server;
const reg = /(?<content>自检)/;

module.exports = {
  name: 'self-check',
  main: ({ data }) => {
    onMsg(data, async (msg) => {
      const res = reg.exec(msg);
      if (!res?.groups?.content) return;
      let serverStatus = false;
      try {
        await request({ url: baseUrl + '/check', method: 'GET' })
        serverStatus = true
      }catch{}
      return {
        message: `self-check: 
  服务端${serverStatus ? '已' : '未'}开启`
      }
    }, { checkAdmin: true, checkAt: true, checkName: true })
  }
}
